<!--
 * @Author: wangding
 * @Date: 2020-11-11 15:58:31
 * @LastEditTime: 2021-02-03 17:09:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sale\add.vue
-->
<template>
    <div class="buyPage-main-box-add">
        <el-dialog
        :title="$t('add')"
        :visible="newVisible"
        width="40%"
        @close="()=>{$store.commit('setNewVisible',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="17" :offset="2">
                    <el-form ref="form" :model="form" label-width="200px" >
                        <el-form-item :label="$t('wifi.versionTypeCloud')" prop="websiteType" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-select v-model="form.websiteType" filterable :placeholder="$t('pleaseSelect')">
                                <el-option
                                v-for="item in cloudType"
                                :key="item.id"
                                :label="item.text"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item :label="$t('uploadFile')" prop="file" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <baseFile v-model='form.file' :placeholder="$t('version.versionAdd.pleaseChoose')"></baseFile>
                        </el-form-item>
                        <el-form-item :label="$t('remark')" prop="remark" :rules="[{ required: false, message: $t('index_js_notNull')}]">
                            <el-input
                            type="textarea"
                            :rows="2"
                            :placeholder="$t('common.info.pl-insert-content')"
                            v-model="form.remark">
                            </el-input>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisible',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {

    },
    data() {
        return {
            form:{
                websiteType:"",
                file:"",
                remark:"",
            },
            cloudType:[{
                id:'0',
                text:'Solax Cloud'
            },{
                id:'1',
                text:'QCELLS'
            }]
        };
    },
    computed: {
        newVisible(){
            return this.$store.state.sysStore.newVisible
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async updateUploadPackage(){
            let res = await this.API.updateUploadPackage(this.form)
            if(this.comm.showMsg(res.success,res.msg)){
                this.$emit('uploadData')
                this.$store.commit('setNewVisible',false)
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.updateUploadPackage()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" >
.buyPage-main-box-add{
    .el-form-item__content{
        display: flex;
    }
    .icon-fontsize{
        font-size: 25px;
        margin-left: 10px;
        display: block;
        width: 25px;
        height: 33px;
    }
}
</style>
